#include "widget.h"


Widget::Widget(QWidget *parent)
    : QMainWindow(parent)
{
    setWindowTitle("汽车销售管理系统");
    setFixedSize(750, 500);


    stackedWidget = new QStackedWidget(this);
    stackedWidget->setFixedSize(750, 500);

    manageWidget = new ManageWidget;
    chartWidget = new ChartWidget;
    changePasswordWidget = new ChangePasswordWidget;
    addUserWidget = new AddUserWidget;
    manageDataWidget = new ManageDataWidget;
    showDataWidget = new ShowDataWidget;

    stackedWidget->addWidget(manageWidget);
    stackedWidget->addWidget(chartWidget);
    stackedWidget->addWidget(changePasswordWidget);
    stackedWidget->addWidget(addUserWidget);
    stackedWidget->addWidget(manageDataWidget);
    stackedWidget->addWidget(showDataWidget);
    stackedWidget->setCurrentIndex(0);
    createMenuBar();
}

Widget::~Widget()
{

}

void Widget::createMenuBar()
{
    manageAction = new QAction("品牌车管理", this);
    chartAction = new QAction("销售统计", this);
    quitAction = new QAction("退出", this);
    manageAction->setShortcut(tr("Ctrl+M"));
    chartAction->setShortcut(tr("Ctrl+C"));
    quitAction->setShortcut(tr("Ctrl+Q"));
    manageMenu = menuBar()->addMenu("销售管理");
    manageMenu->addAction(manageAction);
    manageMenu->addAction(chartAction);
    manageMenu->addSeparator();
    manageMenu->addAction(quitAction);

    changePasswordAction = new QAction("修改密码");
    addUserAction = new QAction("增删账号");
    changePasswordAction->setShortcut(tr("Ctrl+P"));
    addUserAction->setShortcut(tr("Ctrl+A"));
    passwordMenu = menuBar()->addMenu("权限管理");
    passwordMenu->addAction(changePasswordAction);
    passwordMenu->addAction(addUserAction);

    manageDataAction = new QAction("管理数据");
    showDataAction = new QAction("查看数据");
    manageDataAction->setShortcut(tr("Ctrl+D"));
    showDataAction->setShortcut(tr("Ctrl+U"));
    dataMenu = menuBar()->addMenu("数据");
    dataMenu->addAction(manageDataAction);
    dataMenu->addAction(showDataAction);

    connect(manageAction, SIGNAL(triggered()), this, SLOT(on_manageMenu_clicked()));
    connect(chartAction, SIGNAL(triggered()), this, SLOT(on_chartMenu_clicked()));
    connect(quitAction, SIGNAL(triggered()), this, SLOT(on_quitMenu_clicked()));
    connect(changePasswordAction, SIGNAL(triggered()), this, SLOT(on_changePasswordAction_clicked()));
    connect(addUserAction, SIGNAL(triggered()), this, SLOT(on_addUserAction_clicked()));
    connect(manageDataAction, SIGNAL(triggered()), this, SLOT(on_manageDataAction_clicked()));
    connect(showDataAction, SIGNAL(triggered()), this, SLOT(on_showDataAction_clicked()));
}

void Widget::on_chartMenu_clicked()
{
    stackedWidget->setCurrentIndex(1);
}
void Widget::on_manageMenu_clicked()
{
    stackedWidget->setCurrentIndex(0);
}
void Widget::on_quitMenu_clicked()
{
    this->close();
}
void Widget::on_changePasswordAction_clicked()
{
    stackedWidget->setCurrentIndex(2);
}
void Widget::on_addUserAction_clicked()
{
    stackedWidget->setCurrentIndex(3);
}
void Widget::on_manageDataAction_clicked()
{
    stackedWidget->setCurrentIndex(4);
}
void Widget::on_showDataAction_clicked()
{
    stackedWidget->setCurrentIndex(5);
}
